<?php
/**
 * 工作
 * @author diccn
 * @version TS3.0
 */
class JobAction extends Action 
{
	/**
	 * 工作列表
	 * 
	 * @author diccn
	 * 2014-9-7
	 */
	public function index(){
		$list = D('Job')->where(array('status'=>1))->order("ctime DESC")->findAll();
		foreach ( $list as $key=>$val ){
			$list[$key]['ctime'] = friendlyDate($val['ctime'],'ymd');
			$list[$key]['userInfo'] =  model('User')->getUserInfo($val['uid']);
			$data['list'][$list[$key]['ctime']][] = $list[$key];
		}
		$this->assign($data);
		$this->display();
	}
	
	/**
	 * 发布工作
	 * 
	 * @author diccn
	 * 2014-9-7
	 */
	public function release(){
		$this->display();
	}
	/**
	 * 执行发布工作
	 * 
	 * @author diccn
	 * 2014-9-27
	 */
	public function doRelease(){
		$data['uid'] = $this->mid;
		$data['company'] = t($_POST['company']);
		$data['job'] = t($_POST['job']);
		$data['place'] = t($_POST['place']);
		$data['url'] = t($_POST['url']);
		$data['user'] = t($_POST['user']);
		$data['email'] = t($_POST['email']);
		$data['user_place'] = t($_POST['user_place']);
		$data['tel'] = t($_POST['tel']);
		$data['ctime'] = $data['mtime'] = time();
		if($id = D('Job')->add($data)){
			unset($data);
			$data['jumpUrl'] = U('public/job/preview',array('id'=>$id));
			$this->ajaxReturn($data,'操作成功',"1");
		}else{
			$this->ajaxReturn('','操作失败',"0");
		}
	}
	/**
	 * 预览
	 * 
	 * @author diccn
	 * 2014-9-27
	 */
	public function preview(){
		$id = t($_GET['id']);
		$data['job'] = D('Job')->find($id);
		$data['job']['userInfo'] =  model('User')->getUserInfo($data['job']['uid']);
		$this->assign($data);
		$this->display();
	}
}